/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            shopHouseManageInfo: {
                shopHouses: [],
                total: 0,
                records: 1,
                moreCondition: false,
                shId: '',
                shTypes: [],
                conditions: {
                    shName: '',
                    shId: '',
                    shType: '',
                    shopId: ''
                }
            }
        },
        _initMethod: function () {
            $that.shopHouseManageInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
            $that._listShopHouses(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('s_shop_house', "sh_type", function (_data) {
                $that.shopHouseManageInfo.shTypes = _data;
            });
        },
        _initEvent: function () {
            vc.on('shopHouseManage', 'listShopHouse', function (_param) {
                $that._listShopHouses(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listShopHouses(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listShopHouses: function (_page, _rows) {
                $that.shopHouseManageInfo.conditions.page = _page;
                $that.shopHouseManageInfo.conditions.row = _rows;
                let param = {
                    params: $that.shopHouseManageInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/shopHouse.queryShopHouse',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.shopHouseManageInfo.total = _json.total;
                        $that.shopHouseManageInfo.records = _json.records;
                        $that.shopHouseManageInfo.shopHouses = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.shopHouseManageInfo.records,
                            dataCount: $that.shopHouseManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddShopHouseModal: function () {
                vc.emit('addShopHouse', 'openAddShopHouseModal', {});
            },
            _openEditShopHouseModel: function (_shopHouse) {
                vc.emit('editShopHouse', 'openEditShopHouseModal', _shopHouse);
            },
            _openDeleteShopHouseModel: function (_shopHouse) {
                vc.emit('deleteShopHouse', 'openDeleteShopHouseModal', _shopHouse);
            },
            //查询
            _queryShopHouseMethod: function () {
                $that._listShopHouses(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetShopHouseMethod: function () {
                $that.shopHouseManageInfo.conditions.shId = "";
                $that.shopHouseManageInfo.conditions.shName = "";
                $that.shopHouseManageInfo.conditions.shType = "";
                $that._listShopHouses(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.shopHouseManageInfo.moreCondition) {
                    $that.shopHouseManageInfo.moreCondition = false;
                } else {
                    $that.shopHouseManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
